<template>
    <div class="taskMoudle AuditModules">
        <div class="task-header">
           <!-- <span class="taskTxt" v-if="infoData">当前任务：{{infoData.task_name}} {{infoData.task_status_str}} ({{infoData.sub_set_name}} {{infoData.file_name}})</span> -->
		   <span class="taskTxt" v-if="infoData">当前任务：{{infoData.task_name}} ({{infoData.task_status_str}}) - {{infoData.user_name}} - {{infoData.update_time}} </span>
            <el-button size="small" class="task-switch" @click="$router.push({path:'/AuditList'})">切换任务</el-button>
        </div>
        <div class="content" v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
             <el-col :span="24">
                <div class="task-screen clearfix">
					<el-col :span="24" class="task-table">
						<div class="table-drag">
						 <div id="box">
							<v-table v-on:task-table="taskTable" :queryData='queryData'>
								 <span slot="title">审核数据 </span>
								 <span slot="list">
								 </span>
								 <div class="Paginations" slot="cont">
									 <div class="ToexamineBtn">
										 <el-popover
										  placement="bottom"
										  width="160"
										  v-model="from.visible"
										  trigger="click">
										  <el-input type="textarea" autosize placeholder="请输入内容" v-model="from.textarea"></el-input>
										  <div style="text-align: right; margin-top: 5px;">
											<el-button size="mini" type="text" @click="closeTask">取消</el-button>
											<el-button type="primary" size="mini"  @click="rejectResult(false)">确定</el-button>
										  </div>
										  <el-button slot="reference" size="mini" :disabled='taskSelectionData!=""?false:true'>驳回选中</el-button>
										</el-popover>
										 <el-button size="mini" class='btn' @click="handleAuditResult(false)" :disabled='taskSelectionData!=""?false:true'>通过选中</el-button>
										 
										 <el-popover
										 placement="bottom"
										 width="160"
										 v-model="from.visibleInfo"
										 trigger="click">
										 <el-input type="textarea" autosize placeholder="请输入内容" v-model="from.textarea"></el-input>
										 <div style="text-align: right; margin-top: 5px;">
											<el-button size="mini" type="text" @click="closeTask">取消</el-button>
											<el-button type="primary" size="mini" @click="rejectResult(true)">确定</el-button>
										 </div>
										 <el-button slot="reference" size="mini">驳回任务</el-button>
										 </el-popover>
										 <el-button size="mini" class='btn' @click="handleAuditResult(true)">通过任务</el-button>
									 </div>
									 <span class="pull-fl">翻页：</span>
									 <p class="menu3 pull-fl">
										 <em>显示数量：</em>
										 <el-input-number v-model="NewDataList.page_size" @change="changePageSize" :min="1" :max="pagination?pagination.total:1" label="输入条数"></el-input-number>
									 </p>
									 <p class="menu2 pull-fl"><label>共：</label><span>{{pagination?pagination.total:0}}条</span></p>
									 <el-button size="mini" class='btn' @click="NextPage">显示下{{NewDataList.page_size}}条</el-button>
									 <el-button size="mini" class='btn' @click="prevPage">显示上{{NewDataList.page_size}}条</el-button>
								 </div>
							</v-table>
								</div> 
								<div id="line"></div>
						</div>
					</el-col>
										
                </div>
                <div class="task-content" id="taskContent">
                    <el-col :span="24" class="task-map">
						<el-col :span="20" ><v-map ></v-map></el-col>
						<el-col :span="4" ><v-tree v-on:task-tree="taskTree" :infoData='infoData'></v-tree></el-col>
                    </el-col>
                </div>
            </el-col>
        </div>
    </div>
</template>

<script>
import Tree from '../common/TaskModule/tree.vue'
import Map from '../common/TaskModule/map.vue'
import Table from '../common/TaskModule/table.vue'
import Words from '../../services/Words.js'
import bus from '../common/bus';
import TaskMangeService from '../../services/TaskMangeService.js';
import AuditMangeService from '../../services/AuditMangeService.js';
import gcoord from 'gcoord';
export default {
   components: {
       'v-tree':Tree,
       'v-map':Map,
       'v-table':Table,
    },
    data() {
        return {
          TaskMangeService:new TaskMangeService(),
		  AuditMangeService:new AuditMangeService(),
          Words: new Words(),
          infoData:null,
          StatisticsData:null,
          addTaskData:null,
          selectTaskDataList:[],
          queryData:this.$route.query,
          state:1,
          loading:true,  
          TreeData:[],
          pagination:{},
          getCheckedNodes:[],
          NewDataList:{
            batch_id:this.$route.query.task_id?parseInt(this.$route.query.task_id):360,
            check_status:null,
            audit_status:null,
            page_index: 1,
            page_size: 10,
            geo_layers: []
          },
          Heights:0,
					
		dialogVisible:false,
		taskInput:'',
		taskData:[],
		taskId:null,
		taskindex:'',
		taskTableData:[],
		taskTableList:[],
		
		//任务审核
		from:{
			visible:false,
			visibleInfo:false,
			textarea:'',
		},
		taskSelectionData:[], //选中任务数据
        }
    },
    computed:{
    
    },
    created() {
		// this.taskStatistics()
    },
    mounted() {
        let _this=this;
        this.tableDrag();
        bus.$on('load', function (content) {
            _this.loading=content
        })
        //点击左右鼠标；
        bus.$on('LeftJson', (res)=>{
            this.addTaskData = res;
        });
        bus.$on('RightJson', (res)=>{
            let flag = this.queryData?this.queryData.flag == 1:null; 
            if(flag){
                // this.submitTaskList(res) 
            }else{ 
                this.$message.warning('查看状态请勿操作')
            }
        });
        //选择提交列表操作；
        bus.$on('selectTaskData', (res)=>{
            this.taskSubmitListAPI(res)
        });
        //select框选择；
        bus.$on('SelectOptions', (res)=>{
            this.NewDataList.check_status = res.check_status;
            this.NewDataList.audit_status = res.audit_status;
            this.NewDataList.page_index = 1;
            this.NewList()
        });
				
		// 获取地图中选中的数据
		bus.$on('selectedData', (res)=>{
				this.taskTableList = res;
		});
		bus.$on('selectedInfo', (res)=>{
				this.taskTableData = res;
		});
	
		//重构
		// this.obtainTask();
		this.taskDetail();

    },
    methods:{
        //任务提交API
        async taskAuditAPI(paramData){
            let res = await this.TaskMangeService.task_audit(paramData)
            if(res.code==200){
                this.$message.success(res.msg);
                 this.$router.push({path:'/TaskMangeList'})
            }else{
                this.$message.error(res.msg);
            }
        },
        //获取数据处理的统计情况；
        async taskStatistics(){
            let paramData ={id:Number(this.queryData.task_id)};
            let res = await this.TaskMangeService.task_statistics(paramData)
            if(res.code==200){
                this.StatisticsData = res.data
            }else{
                this.$message.error(res.msg);
            }
        },
        //获取任务详情
        async taskDetail(){
            let paramData ={id:Number(this.queryData.task_id),for_audit: true};
            let res = await this.TaskMangeService.task_detail(paramData)
            if(res.code==200){
                this.infoData = res.data;
				bus.$emit('infoData',res.data);
            }else{
                this.$message.error(res.msg);
            }
        },
        //加入待提交列表API
        async taskSubmitListAPI(paramData){
            let res = await this.TaskMangeService.task_submitList(paramData)
            if(res.code==200){
                this.$message.success(res.msg);
                this.taskStatistics();
                this.NewList();
            }else{
                this.$message.error(res.msg);
            }
        },

        //页面显示个数
        changePageSize(val){
            this.NewDataList.page_size=val;
            this.NewList();
        },

        //下一页；
        NextPage(){
            if(this.pagination.page_index<this.pagination.page_count){
                this.NewDataList.page_index += 1;
                this.NewList();
            }else{
                this.$message.warning('已经是最后一页了')
            }
        },
        //显示上一页
        prevPage(){
            if(this.pagination.page_index>1){
                this.NewDataList.page_index -= 1;
                this.NewList();
            }else{
                this.$message.warning('没有上一页了')
            }
        },
        taskTree(data,CheckedNodes){
          this.NewDataList.geo_layers=data;
          this.NewList();
        },

        //返回新数据列表
        async NewList(){
            this.NewDataList.id=Number(this.queryData.task_id);
            let res = await this.TaskMangeService.task_contents(this.NewDataList);
            if(res.code == 200){
                this.pagination = res.data.pagination;
                bus.$emit('pagination',res.data.pagination)
                if(res.data.list[0]!=undefined){
                    let geoJson=JSON.parse(JSON.stringify(res.data.list[0].geo_json));
                    var result = gcoord.transform(geoJson, gcoord.WebMercator,gcoord.BD09 );
                    this.TemporaryPoint=this.DataContrast(result.coordinates,result.type);
                }else{
                    this.TemporaryPoint=[] 
                }
                bus.$emit('Treedata', this.gcoordInfo(res.data.list),this.TemporaryPoint);
            
            }
        },
        //数据类型对比
        DataContrast(cont,type){
            var x=[];
            switch (type)
            {
            case 'Point':x=[cont[0],cont[1]];
            break;
//             case 'MultiLineString':x=[cont[0][0][0],cont[0][0][1]];
//             break;
            case 'MultiPolygon':x=[cont[0][0][0][0],cont[0][0][0][1]];
            break;
						case 'Polygon':x=[cont[0][0][0],cont[0][0][1]];
						break;
						case 'LineString':x=[cont[0][0],cont[0][1]];
						break;
            }
            return x;
        },

        //地图坐标转化
        gcoordInfo(content){
            this.NewData=[];
            if(content!=[]){
            for(let i=0;i<content.length;i++){
                var newLayer=content[i].geo_layer;
                var newGeojson = content[i].geo_json;
                gcoord.transform( newGeojson, gcoord.WebMercator,gcoord.BD09 );
                let Maplist={
                ColorProperty:this.ColorContrast(content[i]) || 106000,
                geo_layer:newLayer,
                Point:newGeojson.coordinates,
                type:content[i].geo_json.type,
                rest:content[i],
				logintxt:this.$route.path,
                }
                this.NewData.push(Maplist)
            }
            }
            return this.NewData
        },

        ColorContrast(data){
            var x='';
            if(data.submitted==false){
                x=106001;
            }else if(data.submitted==true&&data.audit_status==106010){
                x=106010;
            }else if(data.submitted==true&&data.audit_status==106020){
                x=106020;
            }else if(data.submitted==true&&data.audit_status==106030){
                x=106030;
            }
            return x;
        },
        tableDrag(){
            let _this=this;
            _this.$comPlugIn.dragBoxInfo('box','line','taskContent')
        },
				
	//重构

	//提交任务
	async submitTask(){
		let parmes = {
			"id": this.taskId
		}
		let res = await this.TaskMangeService.submitAudit(parmes);
		if(res.code==200){
			this.obtainTask();
		}
	},
	
	//table
	async taskTable(obj,datalist){
		if(obj == 'x6'){
			this.taskSelectionData = datalist;
		}else if(obj == 'x4'){
			this.NewDataList.page_index = 1;
			this.NewDataList.is_modify=datalist;
			this.NewList();
		}
	},
	
	//任务审核
	handleAuditResult(obj){ //通过选中
		let parmes = {};
		if(obj){
			parmes.task_id = Number(this.queryData.task_id);
			this.taskAdoptApi(parmes);
		}else{
			parmes.task_id = Number(this.queryData.task_id);
			parmes.data_list = this.taskSelectionData;
			parmes.adopt = 106020;
			this.taskSelection(parmes);
		}
	},
	
	rejectResult(obj){ //驳回选中
		let parmes = {};
		if(obj){
			parmes.task_id = Number(this.queryData.task_id);
			parmes.remark = this.from.textarea;
			this.taskOverruledApi(parmes);
		}else{
			parmes.task_id = Number(this.queryData.task_id);
			parmes.data_list = this.taskSelectionData;
			parmes.adopt = 106030;
			parmes.remark = this.from.textarea;
			this.taskSelection(parmes);
		}
	},
	//加入驳回清单API
	async taskOverruledApi(obj){
		let res = await this.AuditMangeService.task_overruled(obj);
		if (res.code == 200) {
			this.closeTask();
			this.NewList();
			this.$message.success(res.msg);
		} else {
			this.$message.error(res.msg)
		}
	},
	//任务通过审核API
	async taskAdoptApi(obj){
		let res = await this.AuditMangeService.task_adopt(obj);
		if (res.code == 200) {
			this.closeTask();
			this.NewList();
			this.$message.success(res.msg);
		} else {
			this.$message.error(res.msg)
		}
	},
	
	//驳回选中通过选中
	async taskSelection(obj){
		let res = await this.AuditMangeService.task_selection(obj);
		if (res.code == 200) {
			this.closeTask();
			this.NewList();
			this.$message.success(res.msg);
		} else {
			this.$message.error(res.msg)
		}
	},
	
	closeTask(){ //关闭任重置数据
		this.from.visible = false;
		this.from.visibleInfo = false;
		this.from.textarea = '';
	}
	
    }
}
</script>

<style>
 @import '../../../static/css/task-moudel.css';
 .task-screen{
	 margin-bottom: 15px;
	 position: relative;
	 z-index: 999;
 }
 .addTask{
	  padding: 6px 10px 15px 0;
 }
 .taskList{
	 margin-top: 20px;
 }
 .taskTitle{
	  font-size: 16px;
    padding-bottom: 5px;
 }
 .taskCont{
	 overflow: hidden;
 }
 .taskCont .fl{
	float: left;
 }
 .taskCont li{
 	list-style: none;
	overflow: hidden;
	border-bottom: 1px solid #ddd;
  padding: 5px;
  margin-bottom: 8px;
	cursor: pointer;
 }
 .taskCont li:hover{
	 background:#f2f2f2;;
 }
 .taskCont i:nth-child(1){padding-right: 6px;}
 .taskCont .el-input{
	 width: calc(100% - 60px);
 }
 .taskCont span.txt em{
	  color: #409eff;
 }
 .taskCont .edit{
	 float: right;
 }
 .taskCont .edit i{
	 padding-right: 0;
 }
 .taskCont i{
 	cursor: pointer;
	padding-top: 4px;
  font-size: 15px;
  font-weight: 600;
 }
 .taskActive{
	  background: #f2f2f2;;
    padding: 3px 2px;
 }
 .Paginations{
	 float: right;
	 margin-left: 10px;
	 font-weight: initial;
 }
 .Paginations .menu3,.Paginations .menu2{
	 margin: 0 10px;
 } 
 .AuditModules .Paginations{
	margin-left: -15px;
 }
 .ToexamineBtn{float: left;margin-right: 15px;}
</style>



